package core

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
)

// GetCore get master server entity
func GetCore() *Core {
	return _Core
}

// AddSv 向core中添加Svr
func AddSv(servers ...ISv) {
	_Core.AddSv(servers...)
}

// StartSv start all registered Serves
func StartSv() {
	_Core.StartSv()
}

func WaitTermSignal() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM)
	go func() {
		<-c
		fmt.Println("收到信号TERM，退出中...")
		close(GetCore().Signal.Stop)
	}()
	<-GetCore().Signal.Stopped
}

func BindMsgExec(tp MsgType, exec func(*Msg)) {
	_Core.MsgExecMap[tp] = exec
}

func AddMsg(msg *Msg) {
	_Core.MsgChan <- msg
}
